<template>
  <el-container>
    <el-main>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>系统资源更新</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="updateResources">批量更新</el-button>
        </div>

        <el-table
          :data="tableData"
          stripe
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
          />

          <el-table-column
            prop="title"
            label="标题"
            width="180"
          />
          <el-table-column
            prop="explain"
            label="说明"
          />
          <el-table-column
            label="操作"
            width="180"
          >
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="updateResource(scope.row.url)">更新</el-button>
            </template>
          </el-table-column>
        </el-table>

      </el-card>

    </el-main>
  </el-container>
</template>

<style>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

</style>

<script>
import request from '@/utils/request'
export default {
  data: function() {
    return {
      tableData: [{
        title: '更新文件上传路径',
        explain: '将资源类型作为文件上传路径的一份子，但是需要将数据库中的文件路径保存到redis中，以实现加载时动态添加访问路径',
        url: '/preset/resource-update/source_type_update'
      }],
      multipleSelection: []
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    updateResource: function(url) {
      request({
        url: url,
        method: 'post',
        data: {}
      }).then(res => {
        if (res.result) {
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      }).catch(() => { this.$progress.done() })
    },
    updateResources: function() {
      if (this.multipleSelection) {
        this.multipleSelection.forEach((select) => {
          this.updateResource(select.url)
        })
      }
    }
  }
}
</script>
